<body>
    <h2>咨询级别</h2>
    <div style="margin:10px 0;"></div>
    <table id="list"></table>
    <div id="dlg" class="easyui-dialog" style="width:500px;height:400px;padding:10px 20px"
            closed="true" buttons="#dlg-buttons">
        <div class="ftitle">咨询级别</div>
        <form id="fm" method="post" novalidate>
            <div class="fitem">
                <label>名称:</label>
                <input name="name" class="easyui-validatebox" required="true">
            </div>
            <div class="fitem">
                <label>描述:</label>
                <textarea name="description" style="height:60px;width:200px"></textarea>
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="consultTypeJs.save()">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
    </div>

    <script type="text/javascript">
    (function(consultTypeJs, $, undefined ) {    
    var propertyGridData;
	$('#list').datagrid({
		title:'咨询级别',
		iconCls:'icon-save',
		height:400,
		fitColumns:true,
		singleSelect:true,
		url:null,
		frozenColumns:[[    
	                    {title:'ID',field:'id',width:80,sortable:true}  
	                ]],  
	    columns:[[
	             	{title:'名称',field:'name',width:80,sortable:true},
	             	{title:'描述',field:'description',width:80,sortable:true},
	             ]],
		pagination:false,
		toolbar:[{  
            id:'btnadd',  
            text:'添加',  
            iconCls:'icon-add',  
            handler:newCT
        },{  
            id:'btnupdate',  
            text:'修改',  
            iconCls:'icon-edit',  
            handler:editCT
        },'-',{  
            id:'btndelete',  
            text:'删除',   
            iconCls:'icon-remove',  
            handler:destroyCT 
        },{
        	id:'btnrefresh',
        	text:'刷新',
        	iconCls:'icon-reload',
        	handler:refresh
        }],
	    onLoadSuccess: function(){   
	    }  
	});
	
	consultTypeJs.init = function(){
		
		refresh();
	}
	
	consultTypeJs.loadCTData = function(result){
    	var res = result.result;
        if(res == "SUCCESS")
        {
        	var payload = jQuery.parseJSON(result.payload.value);
        	$('#list').datagrid('loadData',payload);
        }else if(res == "COMPONENT_ERROR")
        {
        	$.messager.alert("Error",result.payload.value);
        }else
        {
        	$.messager.alert("Error",result.result);
        }
	};
	consultTypeJs.simpleResultHanding = function(result){
    	var res = result.result;
        if(res == "SUCCESS")
        {
        	$.messager.show({
                title: 'success',
                msg: "success"
            });
        	refresh();
        }else if(res == "COMPONENT_ERROR")
        {
        	$.messager.alert("Error",result.payload.value);
        }else
        {
        	$.messager.alert("Error",result.result);
        }
	};
	
    var url;
    function newCT(){
        $('#dlg').dialog('open').dialog('setTitle','添加类型');
        $('#fm').form('clear');
        url = 'dispatch/manage/consultLevel/add';
    }
    function refresh(){
    	workbenchJs.loadData("dispatch/manage/consultLevel/all",consultTypeJs.loadCTData,"查询咨询级别");
    }
    function editCT(){
        var row = $('#list').datagrid('getSelected');
        if (row){
            $('#dlg').dialog('open').dialog('setTitle','编辑类型');
            $('#fm').form('clear');
            $('#fm').form('load',row);
            url = 'dispatch/manage/consultLevel/update?id='+row.id;
        }else
        {
        	$.messager.alert("Error",'请先选择一条记录');
        }
    }
    consultTypeJs.save = function(){
        $('#fm').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                var result = eval('('+result+')');
                if (result.result == "SUCCESS"){
                    $.messager.show({
                        title: 'SUCCESS',
                        msg: "success"
                    });
                    $('#dlg').dialog('close');        // close the dialog
                    refresh();
                } else {
                	$.messager.alert("Error",result.result);
                }
            }
        });
    }
    function destroyCT(){
        var row = $('#list').datagrid('getSelected');
        if (row){
        	workbenchJs.loadData("dispatch/manage/consultLevel/delete?id="+row.id,consultTypeJs.simpleResultHanding,"删除咨询级别");
        }
    }
    }( window.consultTypeJs = window.consultTypeJs || {}, jQuery ));

    $(function(){
    	consultTypeJs.init();
    });
    	

    </script>
    <style type="text/css">
        #fm{
            margin:0;
            padding:10px 30px;
        }
        .ftitle{
            font-size:14px;
            font-weight:bold;
            padding:5px 0;
            margin-bottom:10px;
            border-bottom:1px solid #ccc;
        }
        .fitem{
            margin-bottom:5px;
        }
        .fitem label{
            display:inline-block;
            width:80px;
        }
    </style>